#ifndef Action_H
#define Action_H
#include "utility.h"
//(*Headers(Action)
#include <wx/panel.h>
#include <wx/button.h>
#include <wx/dc.h>
#include <wx/timer.h>
//*)
#include <boost/function.hpp>
using namespace std;

typedef boost::function<void (SLayer *)> OnAddLayerFun;
typedef boost::function<void (void)> OnDelActionFun;
typedef boost::function<void (void)> OnDelLayerFun;

class Action: public wxWindow
{
public:
	Action(wxWindow* parent,wxWindowID id=wxID_ANY,const wxPoint& pos=wxDefaultPosition,const wxSize& size=wxDefaultSize);
	virtual ~Action();
	void SetFrame(wxString &imageName,int frameNum,int frameSpace)
	{
		m_actionInfo.type = EATSimple;
		m_actionInfo.simple.imageName = imageName;
		m_actionInfo.simple.frameNum = frameNum;
		m_actionInfo.simple.frameSpace = frameSpace;
		m_actionInfo.complex.layerList.clear();
	}
	SActionInfo &GetActionInfo()
	{
		return m_actionInfo;
	}
	void SetActionInfo(SActionInfo &info)
	{
		m_actionInfo = info;
	}
	void AddLayer(SSelImage *p,int x,int y);
	void SetComplexFrameSpace(int frameSpace);
	void ClearLayer();
	void SetOnAddLayer(OnAddLayerFun fun)
	{
		m_onAddLayer = fun;
	}
	void SetOnDelAction(OnDelActionFun fun)
	{
		m_onDelAction = fun;
	}
	void SetOnDelLayer(OnDelLayerFun fun)
	{
		m_onDelLayer = fun;
	}
	void SetSelLayer(SLayer *pLayer);
	void Stop();
protected:

	//(*Identifiers(Action)
	static const long ID_BUTTON1;
	static const long ID_BUTTON2;
	static const long ID_BUTTON_DEL;
	static const long ID_BUTTON_DEL_FRAME;
	//*)
	//(*Declarations(Action)
	wxButton* m_pRunButton;
	wxButton* m_pStopButton;
	wxButton* m_pDelButton;
	wxButton* m_pDelFrameButton;
	//*)
private:
	//(*Handlers(action)
	void OnSize(wxSizeEvent &event);
	void OnRunButtonClick(wxCommandEvent& event);
	void OnStopButtonClick(wxCommandEvent& event);
	void OnPaint(wxPaintEvent& event);
	void OnBackground(wxEraseEvent &event);
	void Draw(wxDC &dc);
	void LeftDown(wxMouseEvent &event);
	void LeftUp(wxMouseEvent &event);
	void MouseMove(wxMouseEvent &event);
	void OnDelAction(wxCommandEvent& event);
	void OnTimer(wxTimerEvent &event);
	void OnDelFrame(wxCommandEvent &event);
	void OnKeyDown(wxKeyEvent& event);
	//*)
	void MoveSelectLayer(int moveX,int moveY);
	//vector<SLayer> m_layerList;
	size_t m_selLayer;
	int m_mouseX;
    int m_mouseY;
	bool m_isRun;
	bool m_drag;
	int m_curDrawFrame;
	OnAddLayerFun m_onAddLayer;
	OnDelActionFun m_onDelAction;
	OnDelLayerFun m_onDelLayer;
	SActionInfo m_actionInfo;
	wxTimer m_timer;
	wxDECLARE_EVENT_TABLE();
};

#endif
